package com.medicine.hbp.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.medicine.hbp.uitl.ToastUtil;
import com.medicine.hbp.R;

public class ChongfuDialog {

	private Activity activity;

	private Dialog dialog;

	private ChongfuDialogListener listener;
	public ChongfuDialog(Activity activity, ChongfuDialogListener listener) {
		this.activity = activity;
		this.listener = listener;
	}

	public void showDetailEditDialog(String name) {
		View view = activity.getLayoutInflater().inflate(R.layout.chongfu_dialog, null);
		LinearLayout layout01=(LinearLayout) view.findViewById(R.id.layout_01);
		LinearLayout layout02=(LinearLayout) view.findViewById(R.id.layout_02);
		LinearLayout layout03=(LinearLayout) view.findViewById(R.id.layout_03);
		LinearLayout layout04=(LinearLayout) view.findViewById(R.id.layout_04);
		LinearLayout layout05=(LinearLayout) view.findViewById(R.id.layout_05);

		final ImageView Img01=(ImageView) view.findViewById(R.id.img_01);
		final ImageView Img02=(ImageView) view.findViewById(R.id.img_02);
		final ImageView Img03=(ImageView) view.findViewById(R.id.img_03);
		final ImageView Img04=(ImageView) view.findViewById(R.id.img_04);
		final ImageView Img05=(ImageView) view.findViewById(R.id.img_05);

		dialog = new Dialog(activity, R.style.transparentFrameWindowStyle);
		dialog.setContentView(view, new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT));
		Window window = dialog.getWindow();
		if(name.equals("无重复")){
			Img01.setImageResource(R.mipmap.vote_1);
			Img02.setImageResource(R.mipmap.vote_2);
			Img03.setImageResource(R.mipmap.vote_2);
			Img04.setImageResource(R.mipmap.vote_2);
			Img05.setImageResource(R.mipmap.vote_2);
		}else if(name.equals("每天")){
			Img01.setImageResource(R.mipmap.vote_2);
			Img02.setImageResource(R.mipmap.vote_1);
			Img03.setImageResource(R.mipmap.vote_2);
			Img04.setImageResource(R.mipmap.vote_2);
			Img05.setImageResource(R.mipmap.vote_2);
		}else if(name.equals("每周")){
			Img01.setImageResource(R.mipmap.vote_2);
			Img02.setImageResource(R.mipmap.vote_2);
			Img03.setImageResource(R.mipmap.vote_2);
			Img04.setImageResource(R.mipmap.vote_1);
			Img05.setImageResource(R.mipmap.vote_2);
		}else if(name.equals("仅周末")){
			Img01.setImageResource(R.mipmap.vote_2);
			Img02.setImageResource(R.mipmap.vote_2);
			Img03.setImageResource(R.mipmap.vote_2);
			Img04.setImageResource(R.mipmap.vote_1);
			Img05.setImageResource(R.mipmap.vote_2);
		}else if(name.equals("每月")){
			Img01.setImageResource(R.mipmap.vote_2);
			Img02.setImageResource(R.mipmap.vote_2);
			Img03.setImageResource(R.mipmap.vote_2);
			Img04.setImageResource(R.mipmap.vote_2);
			Img05.setImageResource(R.mipmap.vote_1);
		}
		layout01.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Img01.setImageResource(R.mipmap.vote_1);
				Img02.setImageResource(R.mipmap.vote_2);
				Img03.setImageResource(R.mipmap.vote_2);
				Img04.setImageResource(R.mipmap.vote_2);
				Img05.setImageResource(R.mipmap.vote_2);
				listener.onSelect("无重复","1");
				dialog.dismiss();
			}
		});
		layout02.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Img01.setImageResource(R.mipmap.vote_2);
				Img02.setImageResource(R.mipmap.vote_1);
				Img03.setImageResource(R.mipmap.vote_2);
				Img04.setImageResource(R.mipmap.vote_2);
				Img05.setImageResource(R.mipmap.vote_2);
				listener.onSelect("每天","2");
				dialog.dismiss();
			}
		});
		layout03.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Img01.setImageResource(R.mipmap.vote_2);
				Img02.setImageResource(R.mipmap.vote_2);
				Img03.setImageResource(R.mipmap.vote_1);
				Img04.setImageResource(R.mipmap.vote_2);
				Img05.setImageResource(R.mipmap.vote_2);
				listener.onSelect("每周","3");
				dialog.dismiss();
			}
		});
		layout04.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Img01.setImageResource(R.mipmap.vote_2);
				Img02.setImageResource(R.mipmap.vote_2);
				Img03.setImageResource(R.mipmap.vote_2);
				Img04.setImageResource(R.mipmap.vote_1);
				Img05.setImageResource(R.mipmap.vote_2);
				listener.onSelect("仅周末","4");
				dialog.dismiss();
			}
		});
		layout05.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Img01.setImageResource(R.mipmap.vote_2);
				Img02.setImageResource(R.mipmap.vote_2);
				Img03.setImageResource(R.mipmap.vote_2);
				Img04.setImageResource(R.mipmap.vote_2);
				Img05.setImageResource(R.mipmap.vote_1);
				listener.onSelect("每月","5");
				dialog.dismiss();
			}
		});

		// 设置显示动画
		window.setWindowAnimations(R.style.show_photograpDialog_animstyle);
		dialog.show();
		dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
				WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
	}
	public interface ChongfuDialogListener {
		public void onSelect(String content,String type);
		public void onCancel();
	}
	/**
	 * 让软键盘消失
	 */
	private void InputMethodc() {
		View v = dialog.getWindow().getDecorView();
		// 得到InputMethodManager的实例
		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
		// 如果开启
		if (imm.isActive()) {
			imm.hideSoftInputFromWindow(v.getWindowToken(),0);
			// 关闭软键盘，开启方法相同，这个方法是切换开启与关闭状态的
		}
	}
}